package fsoft.com.vn.directory.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import fsoft.com.vn.directory.form.Business;
import fsoft.com.vn.directory.service.BusinessService;

@Controller
public class BusinessController {

	@Autowired
	private BusinessService businessService;


	@RequestMapping("/business")
	public String listBusinesss(Map<String, Object> map, HttpServletRequest req) {

		int page = 1;
		if(req.getParameter("page") != null){
			page = Integer.parseInt(req.getParameter("page"));
		}
		map.put("business", new Business());
		map.put("businessList", businessService.listBusiness(page));
		map.put("curpage", page);
		map.put("nextpage", page+1);
		if(page > 1) map.put("prepage", page-1);

		return "business";
	}
	
	@RequestMapping("/searchbusiness")
	public String search(Map<String, Object> map,@RequestParam(value = "businessname") String businessname, @RequestParam(value = "siccode") String siccode) {
		map.put("business", new Business());
		map.put("businessList", businessService.search(businessname,siccode));
		return "business";
	}
	
	
}
